package com.maozzi.gateway.enums;

import com.maozzi.common.enums.BizEnum;
import lombok.Getter;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 用户类型枚举类型
 *
 * @author maozi
 */
public enum UserTypeEnum implements BizEnum<Integer> {

    /**
     * 用户类型，1 普通用户，2 管理员， 3 超级管理员
     */
    NORMAL(1, "普通用户"),
    ADMIN(2, "管理员"),
    SUPER_ADMIN(3, "超级管理员"),
    ;

    private final Integer code;

    private final String description;

    UserTypeEnum(Integer code, String description) {
        this.code = code;
        this.description = description;
    }


    public final static Map<Integer, UserTypeEnum> CONTAINER = new ConcurrentHashMap<>(3);

    static {
        for (UserTypeEnum typeEnum : UserTypeEnum.values()) {
            CONTAINER.put(typeEnum.code, typeEnum);
        }
    }

    @Override
    public Integer getCode() {
        return this.code;
    }

    @Override
    public String description() {
        return this.description;
    }

    @Override
    public BizEnum<Integer> value(Integer code) {
        for (UserTypeEnum i : UserTypeEnum.values()) {
            if (i.getCode().intValue() == code) {
                return i;
            }
        }
        return null;
    }
}
